﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace IRC.NET.Commands
{
    public abstract class TwoWayCommandBase : CommandBase
    {
        public TwoWayCommandBase(string prefix)
            : base(prefix, true)
        {

        }

        public abstract bool IsResponse(ServerReply message);
        public abstract bool ProcessResponse(ServerReply message);

        protected bool IsMatch(string message, string pattern)
        {
            return (Regex.IsMatch(message, pattern));
        }

        protected IDictionary<string, string> GetResponseParameters(string response, string pattern)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            if (Regex.IsMatch(response, pattern, RegexOptions.IgnoreCase))
            {
                Match match = Regex.Match(response, pattern, RegexOptions.IgnoreCase);

                foreach (Group group in match.Groups)
                {
                    if (group.Success)
                    {
                        dictionary.Add(group.ToString(), group.Value);
                    }
                }
            }

            return (dictionary);
        }
    }
}
